module.exports = {
	/**
	 * 查询多条记录 分页
	 * @url admin/user/sys/getList 前端调用的url参数地址
	 * data 请求参数 说明
	 * @params {Number}         pageIndex 当前页码
	 * @params {Number}         pageSize  每页显示数量
	 * @params {Array<Object>}  sortRule  排序规则
	 * @params {object}         formData  查询条件数据源
	 * @params {Array<Object>}  columns   查询条件规则
	 * res 返回参数说明
	 * @params {Number}         code      错误码，0表示成功
	 * @params {String}         msg       详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, formData } = data;
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		let dbName = "uni-id-users"; // 表名

		if (userInfo.role.includes("admin")) {
			if (formData.platform) {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						platform: formData.platform
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			} else {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						//platform要么为ks,tt,weixin，其他类型不展示
						platform: _.or(_.eq("tt"), _.eq("ks"), _.eq("weixin"), _.eq("h5"), _.eq("app"), _.eq("h5-weixin"))
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			}
			return res;
		}

		if (userInfo.role.includes("agent")) {
			if (formData.platform) {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						platform: formData.platform,
						invite_code: uid
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			} else {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						invite_code: uid,
						//platform要么为ks,tt,weixin，其他类型不展示
						platform: _.or(_.eq("tt"), _.eq("ks"), _.eq("weixin"), _.eq("h5"), _.eq("app"), _.eq("h5-weixin"))
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			}
			return res;
		}

		if (userInfo.role.includes("middleman")) {
			if (formData.platform) {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						platform: formData.platform,
						middleman_id: uid
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			} else {
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: {
						middleman_id: uid,
						//platform要么为ks,tt,weixin，其他类型不展示
						platform: _.or(_.eq("tt"), _.eq("ks"), _.eq("weixin"), _.eq("h5"), _.eq("app"), _.eq("h5-weixin"))
					},
					// 默认排序规则
					sortArr: [{
						name: "register_date",
						type: "desc"
					}],
				});
			}
			return res;
		}

	}

}
